<html>
<head><meta charset="utf-8"><title>Are staticlibs compatible across vendors and environments? · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html">Are staticlibs compatible across vendors and environments?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240840936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240840936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240840936">(May 31 2021 at 14:38)</a>:</h4>
<p>Hey, if you distribute a <code>unknown-unknown</code> or a <code>unknown-none</code> staticlib, is it compatible with more specific environments and vendors? For example if I distribute a <code>aarch64-unknown-none</code> staticlib, could you later compile that single staticlib for both ARM Linux and ARM Windows? (provided using a linker that can understand ELF on both hosts)</p>



<a name="240841447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240841447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240841447">(May 31 2021 at 14:43)</a>:</h4>
<p>There are two main variants for staticlibs. BSD ar and GNU ar. Both are incompatible with each other. Linux uses GNU ar. I am not sure what variant Windows uses.</p>



<a name="240844931"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240844931" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240844931">(May 31 2021 at 15:15)</a>:</h4>
<p>Windows uses a COFF archive.</p>



<a name="240845125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240845125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240845125">(May 31 2021 at 15:17)</a>:</h4>
<p>The object formats aren't compatible between Windows and Linux either.</p>



<a name="240845248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240845248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240845248">(May 31 2021 at 15:18)</a>:</h4>
<p>If you had a specific linker that worked on all platforms and supported some common format for archives and objects, then there wouldn't be any issues, though, as the machine code within the objects is conceptually independent of the OS.</p>



<a name="240846185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240846185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240846185">(May 31 2021 at 15:28)</a>:</h4>
<p>The ABI might differ though, right? Maybe not for AArch64</p>



<a name="240847534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240847534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chris Denton <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240847534">(May 31 2021 at 15:42)</a>:</h4>
<p><a href="https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#archive-member-headers">Windows ar</a> is gnu compatible (there's an extra "/" member but it's technically redundant). However the object files it contains are indeed <a href="https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#coff-file-header-object-and-image">COFF</a>. Also Windows libraries can contain things which aren't objects files, or object files that contain Windows specific metadata, etc.</p>



<a name="240847895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240847895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240847895">(May 31 2021 at 15:45)</a>:</h4>
<p>Unix static libraries can also contain non-object files for as long as they come after all object files. For example rlibs contain <code>lib.rmeta</code>.</p>



<a name="240867446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240867446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240867446">(May 31 2021 at 20:08)</a>:</h4>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> So that does that imply that *NIX -&gt; *NIX is trivially possible? E.g. <code>aarch64-unknown-none</code> with <code>aarch64-unknown-linux-gnu</code>?</p>



<a name="240867695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240867695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240867695">(May 31 2021 at 20:12)</a>:</h4>
<p><span class="user-mention" data-user-id="219696">@XAMPPRocky</span> In theory it should be. Various non-Rust tools count on that (typically in the reverse direction: they build for somearch-unknown-linux-gnu, carefully ensuring no references to libraries or unavailable builtin symbols, and use the resulting object files for embedded).</p>



<a name="240867804"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240867804" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240867804">(May 31 2021 at 20:14)</a>:</h4>
<p>In principle there's no fundamental reason that <code>somearch-unknown-unknown</code> object files couldn't work on any <code>somearch-*-*</code> target.</p>



<a name="240867858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240867858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240867858">(May 31 2021 at 20:15)</a>:</h4>
<p>I can potentially imagine scenarios in which code generation might vary slightly, in that <code>somearch-unknown-unknown</code> might avoid references to builtin symbols that <code>somearch-unknown-linux-gnu</code> wouldn't.</p>



<a name="240867862"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240867862" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240867862">(May 31 2021 at 20:15)</a>:</h4>
<p>But it shouldn't be <em>broken</em>, I think.</p>



<a name="240868226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240868226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240868226">(May 31 2021 at 20:20)</a>:</h4>
<p>Right, I’ve just messed with enough with the target code in rustc to know there aren’t really invariants to enforce that compatibility, so there’s nothing stopping an arbitrary environment being incompatible with another. Not that I’m saying there should be something stopping that, but it is why I ask if other people have already tried this.</p>



<a name="240868309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240868309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240868309">(May 31 2021 at 20:21)</a>:</h4>
<p>Many people in C have done things <em>like</em> it. I've never seen it done in Rust.</p>



<a name="240868406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240868406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240868406">(May 31 2021 at 20:23)</a>:</h4>
<p>Also, this won't necessarily work for <em>arbitrary</em> architectures, only those where the ABI for the target is the same on all OSes.</p>



<a name="240868416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240868416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240868416">(May 31 2021 at 20:23)</a>:</h4>
<p>Some architectures have different ABIs on different OSes.</p>



<a name="240868514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240868514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240868514">(May 31 2021 at 20:25)</a>:</h4>
<p>As an example, even if the object file formats were compatible, x86_64 has a different ABI on Windows and on all UNIX variants.</p>



<a name="240868917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240868917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240868917">(May 31 2021 at 20:31)</a>:</h4>
<p>Hmm yeah, I mentioned Linux to Windows as an extreme, but I’m mostly interested in intra-family cross-compilation (BSD -&gt; BSD, Windows -&gt; Windows)</p>
<p>What I’m essentially trying to achieve is distributing a c library with a wide compatibility without having to create artifacts for every platform, since it’s code should be mostly OS and platform agnostic.</p>



<a name="240868923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240868923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240868923">(May 31 2021 at 20:31)</a>:</h4>
<p>Technically the <code>e_ident[EI_OSABI]</code> field in the elf header specifies the target OS, but I believe it is often just ignored.</p>



<a name="240869010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240869010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240869010">(May 31 2021 at 20:32)</a>:</h4>
<p>I am curious what the library will do by the way.</p>



<a name="240870227"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240870227" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240870227">(May 31 2021 at 20:52)</a>:</h4>
<p>Heh, I’m afraid I want to keep that a surprise for now. 😄</p>



<a name="240870515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Are%20staticlibs%20compatible%20across%20vendors%20and%20environments%3F/near/240870515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Are.20staticlibs.20compatible.20across.20vendors.20and.20environments.3F.html#240870515">(May 31 2021 at 20:57)</a>:</h4>
<p>Ok, no problem. I just got even more curious now :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>